Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hack/verify-staging-imports.sh: print actual dependencies #40659

Merged

Conversation

sttts
Copy link
Contributor

@sttts sttts commented Jan 29, 2017

Example:

$ hack/verify-staging-imports.sh
apiserver has a forbidden dependency:

  k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/api/errors
  k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/api/meta
  k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/runtime
  k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/runtime/schema
  k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/util/errors
  k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/util/sets

@sttts sttts added the release-note-none Denotes a PR that doesn't merit a release note. label Jan 29, 2017
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 29, 2017
@k8s-github-robot k8s-github-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 29, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

Needs approval from an approver in each of these OWNERS Files:

We suggest the following people:
cc @zmerlynn
You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-reviewable
Copy link

This change is Reviewable

@sttts
Copy link
Contributor Author

sttts commented Jan 29, 2017

@k8s-bot unit test this

@@ -25,8 +25,20 @@ kube::golang::setup_env


for dep in $(ls -1 ${KUBE_ROOT}/staging/src/k8s.io/); do
if go list -f {{.Deps}} ./vendor/k8s.io/${dep}/... | tr " " '\n' | grep k8s.io/kubernetes | grep -v 'k8s.io/kubernetes/vendor' | LC_ALL=C sort -u | grep -e "."; then
echo "${dep} has a cyclical dependency"
if go list -f "{{.Deps}}" ./vendor/k8s.io/${dep}/... | tr " " '\n' | grep k8s.io/kubernetes | grep -v 'k8s.io/kubernetes/vendor' | LC_ALL=C sort -u | grep -qe "."; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some way to extract the printing logic so we can reasonably prevent client-go from depending on apiserver without copy/pasting this monster?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

certainly this can be abstracted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

certainly this can be abstracted.

Ok, I'm bash challenged. You mind setting it up and then this lgtm.

if go list -f "{{.Deps}}" ./vendor/k8s.io/${dep}/... | tr " " '\n' | grep k8s.io/kubernetes | grep -v 'k8s.io/kubernetes/vendor' | LC_ALL=C sort -u | grep -qe "."; then
echo "${dep} has a cyclical dependency:"
echo
go list -f '{{.ImportPath}} {{.Deps}}' ./vendor/k8s.io/${dep}/... |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liggitt @stevekuznetsov @smarterclayton @ncdc I feel like this deserves some honorable mention or something for most sed pipes I've been in our bash.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely there is a cleaner and more approachable way to do this using the Golang AST API... @deads2k you owe me lunch for making this the first thing I looked at this morning

go list -f '{{.ImportPath}} {{.Deps}}' ./vendor/k8s.io/${dep}/... |
sed 's|^k8s.io/kubernetes/vendor/\([-a-zA-Z./0-9_]*\)|\1:|' | # remove vendor prefix of ImportPath
sed 's| k8s.io/kubernetes/vendor/[-a-zA-Z./0-9_]*||g' | # remove vendored packages
grep k8s.io/kubernetes | # only show packages with k8s.io/kubernetes deps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you put in newlines laters, how is grep working right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if one k8s.io/kubernetes is found it's enough to consider the whole line. If not, ignore the whole line.

@deads2k
Copy link
Contributor

deads2k commented Jan 30, 2017

I'm confident it still exits 1 when it fails. I'm unsure about the pipe monster and a little concerned about finding internal cycles. Is there an easy way to make it workable for client-go to apiserver style deps?

@sttts sttts force-pushed the sttts-print-staging-import-cycles branch from 49642ac to 3e58f7c Compare January 30, 2017 14:58
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 30, 2017
@sttts sttts changed the title hack/verify-staging-imports.sh: print actual dependencies [WIP] hack/verify-staging-imports.sh: print actual dependencies Jan 30, 2017
@sttts
Copy link
Contributor Author

sttts commented Jan 30, 2017

Updated, still WIP. Stepping out for an hour, then testing.

@sttts sttts force-pushed the sttts-print-staging-import-cycles branch 2 times, most recently from 72c26d6 to ea79fe5 Compare January 30, 2017 15:48
@sttts sttts changed the title [WIP] hack/verify-staging-imports.sh: print actual dependencies hack/verify-staging-imports.sh: print actual dependencies Jan 30, 2017
@sttts sttts force-pushed the sttts-print-staging-import-cycles branch from ea79fe5 to 78e7e51 Compare January 30, 2017 15:58
@sttts
Copy link
Contributor Author

sttts commented Jan 30, 2017

@deads2k @stevekuznetsov ptal. #40688 is supposed to fail.

@stevekuznetsov
Copy link
Contributor

I still don't understand why this is a Bash script. The Go team exposes a great library for programatically working with Go source. Writing a short Go script using ast would be simple, would not have worries about return codes, and would not need ugly sed expressions, worries about compatibility ...

@sttts
Copy link
Contributor Author

sttts commented Jan 30, 2017

@stevekuznetsov feel free to rewrite it in Go as a follow-up. IMO it's not really important for this tiny script. We have bash code (look into Makefile.generated_files for instance) which is 3 orders of magnitude more awful and worth the energy spent for a rewrite.

fi
done
RC=0
print_forbidden_imports apimachinery k8s.io/ || RC=1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this ended up a lot better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If at any point you expect set -o errexit to alter the flow of commands inside of print_forbidden_imports -- like, a failure somewhere in there you would expect to exit early ... in this construct, it would not. function_call || something will turn off errexit inside the function and there is no way to turn it back on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. thanks. Those details of shell code...

shift
local RE=""
local SEP=""
for CLAUSE in "$@"; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't this pick up the first argument?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shift above removes it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the shift on line 28

@deads2k
Copy link
Contributor

deads2k commented Jan 30, 2017

lgetm.

@deads2k deads2k added approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jan 30, 2017
@deads2k
Copy link
Contributor

deads2k commented Jan 30, 2017

@eparis don't freak out this time. I'm going to open a pull to add myself to the list

@eparis
Copy link
Contributor

eparis commented Jan 30, 2017

@deads2k RAWR!

@sttts sttts added approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jan 30, 2017
@sttts sttts force-pushed the sttts-print-staging-import-cycles branch from 78e7e51 to 22e9db0 Compare January 30, 2017 16:26
@k8s-github-robot k8s-github-robot assigned spxtr and unassigned deads2k Jan 30, 2017
@spxtr spxtr assigned deads2k and unassigned spxtr Jan 30, 2017
@k8s-github-robot k8s-github-robot assigned jbeda and unassigned deads2k Jan 30, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 40703, 40093, 40618, 40659, 39810)

@k8s-github-robot k8s-github-robot merged commit 2975475 into kubernetes:master Jan 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet